package operation.duoxianliu.demo06;

public class Cup implements Runnable {
    private int cun = 100;

    @Override
    public void run() {
        int a=0;
        while (true) {
            synchronized (this) {
                String name=Thread.currentThread().getName();
                if (cun <= 0) {
                    System.out.println(name+"一共出售了"+a+"个杯子");
                    break;
                }
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(name+"正在出售第"+cun+"个杯子");
                cun--;
                a++;
            }
        }
    }
}